import React from "react";
import { Route } from "react-router-dom";

import Login from "../pages/Login.jsx";
import BwlDetail from "../pages/Detail.jsx";
import Index from "../pages/Index.jsx";
import BwlList from "../pages/bwl/List.jsx";
import Mine from "../pages/bwl/Mine.jsx";
import BwlAdd from "../pages/bwl/Add.jsx";

export const routes = [
    {
        path: "/login",
        component: Login,
    },
    {
        path: "/detail/:id",
        component: BwlDetail,
    },
    {
        path: "/bwl",
        component: Index,
        children: [
            {
                path: "/bwl/list",
                component: BwlList,
            },
            {
                path: "/bwl/add",
                component: BwlAdd,
            },
            {
                path: "/bwl/mine",
                component: Mine,
            },
        ],
    },
];

export default ({ routes }) => {
    return routes.map((item) => {
        return (
            <Route
                key={item.path}
                path={item.path}
                render={(props) => {
                    return (
                        <item.component
                            {...props}
                            routes={item.children || []}
                        />
                    );
                }}
            />
        );
    });
};
